package com.npf.imgserver.controller;


import com.npf.imgserver.common.base.ResultBase;
import com.npf.imgserver.common.enums.ResultCodeEnum;
import com.npf.imgserver.entity.Customer;
import com.npf.imgserver.exception.NormalException;
import com.npf.imgserver.service.api.CustomerService;
import com.npf.imgserver.service.impl.CustomerServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author nipengfei
 * @since 2018-09-22
 */
@Api(value = "/customer", tags = "接入商模块")
@RestController
@RequestMapping("/customer")
public class CustomerController {

    public static final Logger logger = LoggerFactory.getLogger(CustomerController.class);

    @Autowired
    private CustomerService customerService;

    /**
     * 框架测试
     * @return
     */
    @GetMapping("/test")
    public ResultBase frmeworkTest() throws NormalException {
        throw new NormalException("我要测试抛异常");
//        return new ResultBase(ResultCodeEnum.SUCCESS);
    }


    /**
     * 新增接入商信息
     *
     * @return
     */
    @PostMapping("/saveCustomer")
    @ApiOperation(value = "新增接入商信息", notes = "新增接入商信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerName", value = "接入商名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "linkMan", value = "联系人信息", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "contactInfo", value = "联系方式", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "isLock", value = "0 启用 1 禁用 默认启用", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "isDelete", value = "0 正常 1 逻辑删除 默认正常", paramType = "query", dataType = "int"),
    })
    public ResultBase saveCustomer(/*@RequestBody*/ Customer customer) {
        ResultBase resultBase = null;
        try {
            resultBase = customerService.saveCustomer(customer);
        } catch (Exception e) {
            logger.error("新增接入商信息失败", e);
            resultBase.setCodeEnum(ResultCodeEnum.ERROR_SERVER);
        }
        return resultBase;
    }

}

